Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| |||||||||||
Interview Questions and Answers - Order By Newest | |||||||||||
| |||||||||||
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error. For example - interface MyInterface { public void default myMethod(){ } } interface MyInterface2 { public void default myMethod(){ } } class MyClass implements MyInterface,MyInterface2 { } This code will compilation error "Duplicate Default Method" if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces | |||||||||||
| |||||||||||
Ans. No, If both Parent and Derived are outer classes. public class Vehicle { private static String manufacturingDate = "2016"; } public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible } } Yes, If derived is the inner class of Parent. public class Vehicle { private static String manufacturingDate = "2016"; static public class Car extends Vehicle{ public static void main(String args[]){ System.out.println(manufacturingDate); // no problem } } } | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes basic   frequent | |||||||||||
| |||||||||||
Ans. Multiple Inheritance refers to the concept of a class inheriting multiple classes. Example - Class C extends Class A ,Class B. This is not allowed in Java. Multilevel Inheritance refers to the concept of Inheritance in a chain. Example - Class B extends Class A, Class C extends Class B. This is permitted in Java. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts   multiple inheritance  object oriented programming (oops)  oops concepts   multi level inheritance  object oriented programming (oops)  oops concepts Basic   frequent | |||||||||||
| |||||||||||
Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  core oops concepts Asked in 65 Companies basic   frequent | |||||||||||
| |||||||||||
Ans. Composition and Inheritance are the different types of Associations for Classes. Composition is a has-a association between classes. Inheritance is a is-a association between classes. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  composition  object oriented programming (oops)  oops concepts  inheritance  object oriented programming (oops)  oops concepts  association  relationship between objects | |||||||||||
| |||||||||||
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding basic | |||||||||||
| |||||||||||
Ans. dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. This is used to achieve runtime polymorphism in java. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  overriding  runtime polymorphism  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
Ans. Dynamic dispatch in java is also known as runtime polymorphism.It is a process in which a call to an overriden method is resolved at runtime. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  dynamic dispatch  runtime polymorphism  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
Ans. Private variables are not inherited. They are simply ignored and not made part of the derived object body. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  private variables  inheritance  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  private class   private inner class  class hiding  encapsulation  object oriented programming (oops)  oops concepts  inner classes   nested classes | |||||||||||
Very frequently asked. Usually among very first few questions. | |||||||||||
| |||||||||||
Ans. Encapsulation is a feature of OOP's that binds the data and it's associated methods together as a single unit and facilitate protection and data hiding by providing minimal interface to outside. For example - member variables are declared private and are accessed through public methods. Moreover we have private methods that can only be used internally and hence providing minimal interface to outside class through use of public methods. | |||||||||||
Sample Code for encapsulation | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  encapsulation  object oriented programming (oops)  oops concepts  oops  oops concepts  oops features Asked in 4 Companies Basic   frequent | |||||||||||
| |||||||||||
Ans. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops example  oops concepts  oops features Asked in 2 Companies basic   frequent | |||||||||||
| |||||||||||
Ans. Getting parent class object properties into child class is called Inheritance. The process of representing one form into multiple forms is called polymorphism. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts  polymorphism  object oriented programming (oops)  oops concepts Asked in 1 Companies Basic   frequent | |||||||||||
| |||||||||||
Ans. Loose Coupling Facilitates designing complex applications by making them modular. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops concepts  abstraction Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
This question was recently asked at 'Intel'.This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  abstraction  oops concepts Asked in 1 Companies basic | |||||||||||
| |||||||||||
Ans. There are four main OOP concepts in Java. These are: Abstraction. Abstraction means using simple things to represent complexity. We all know how to turn the TV on, but we don?t need to know how it works in order to enjoy it. In Java, abstraction means simple things like objects, classes, and variables represent more complex underlying code and data. This is important because it lets avoid repeating the same work multiple times. Encapsulation. This is the practice of keeping fields within a class private, then providing access to them via public methods. It?s a protective barrier that keeps the data and code safe within the class itself. This way, we can re-use objects like code components or variables without allowing open access to the data system-wide. Inheritance. This is a special feature of Object Oriented Programming in Java. It lets programmers create new classes that share some of the attributes of existing classes. This lets us build on previous work without reinventing the wheel. Polymorphism. This Java OOP concept lets programmers use the same word to mean different things in different contexts. One form of polymorphism in Java is method overloading. That?s when different meanings are implied by the code itself. The other form is method overriding. That?s when the different meanings are implied by the values of the supplied variables. See more on this below. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops concepts Asked in 16 Companies basic   frequent | |||||||||||
| |||||||||||
This question was recently asked at 'MST Solutions'.This question is still unanswered. Can you please provide an answer. | |||||||||||
Sample Code for composition | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  composition  object oriented programming (oops)  oops concepts  oops concepts Asked in 1 Companies basic   frequent | |||||||||||
| |||||||||||
Ans. Overriding refers to the Methods with same name and parameters, such that the later over rides the former method. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops concepts  overriding Asked in 1 Companies basic   frequent | |||||||||||
| |||||||||||
Ans. 1. State Instance variable or member elements forms the object state. 2. Behavior Member functions forms the object behavior 3. Identity Every object has a unique identity within JVM through a unique Id. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops concepts | |||||||||||
| |||||||||||
Ans. Encapsulation facilitates security by hiding data and logic whereas Abstraction simplifies organization of data and related logic. As applications scale, both concepts are required for easy management and maintenance. Encapsulation for security and criss cross communication between objects / modules will make it vulnerable. and Abstraction for better organization that enables better understanding of application code and easy maintainability. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops features  oops concepts | |||||||||||
| |||||||||||
Ans. Method overloading / static polymorphism compared to method overriding / runtime polymorphism has very limited usage as it just opens up an alternate way of defining a different method with the same name. Method Overriding on other hand opens up many other features like contracting , interfacing , pluging development and hence development of libraries and frameworks. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops features  oops concepts | |||||||||||
| |||||||||||
Ans. Encapsulation facilitate hiding and restricted access and hence more of a security feature. Encapsulation is definitely a great feature as when applications expand criss cross communication between objects / modules could lead to blunders. Inheritance facilitates code reuse. Polymorphism comprise of method overloaded ( which to me is negligible usage ) and method overriding. Method overriding is of great usage as it facilitates concept of interfaces and plugin development. So it’s Security / Organization vs Code Reuse / Support for other features like overriding vs Contracts / Plugin Development facilitating the creation of frameworks / libraries. Which is more important may vary from application to application , its scale , its use , its sensitivity etc. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  oops  oops features  oops concepts | |||||||||||
| |||||||||||
This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts expert   rare | |||||||||||
| |||||||||||
Ans. There is one VTable for each class. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding intermediate   rare | |||||||||||
| |||||||||||
Ans. No | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||